Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create constructor for creating allocated BlockArrays #39

Merged
merged 7 commits into from
Dec 2, 2017

Conversation

dlfivefifty
Copy link
Member

• Support BlockArray{Float64}(1:3, 1:3), etc. syntax for creating allocated block arrays

• Deprecate BlockArray(blocks,...) in favour of _BlockArray(blocks,...) to avoid confusion with BlockArray(arr,...) function that converts arr to a BlockArray.

…ocated block arrays

• Deprecate BlockArray(blocks,...) in favour of _BlockArray(blocks,...) to avoid confusion with BlockArray(arr,...) function that converts arr to a BlockArray.
@dlfivefifty
Copy link
Member Author

This addresses #37

@KristofferC
Copy link
Collaborator

KristofferC commented Nov 26, 2017

We should definitely not export a function with an underscore in it (or is this not exported anymore). Also, why can't we just dispatch on Type vs instance to keep it as one function?

Being able to create uninitialized blocks is valuable in my opinion.

@dlfivefifty
Copy link
Member Author

dlfivefifty commented Nov 26, 2017

It isn't exported.

The issue is that one might want to create a BlockArray{Matrix{Float64},2,Matrix{Matrix{Float64}}}. Dispatching differently when the first argument is a Matrix{Matrix{Float64}} vs a Matrix{Float64} is inconsistent. I also think BlockArray and PseudoBlockArray should have consistent syntax.

Because I've added allocating constructors, the need for the BlockArray(blocks,...) constructor is not as big, and I think since it's using internal data it's reasonable for users to need to use BlockArrays._BlockArray(blocks,...) if they want an unitialized BlockArray.

@dlfivefifty
Copy link
Member Author

Alternatively, it could be renamed unallocated_BlockArray.

@KristofferC
Copy link
Collaborator

Base is doing something like BlockArray{...}(uninitialized, ...) wouldn't the same work here?

@dlfivefifty
Copy link
Member Author

Cool! how would I implement that?

@codecov-io
Copy link

codecov-io commented Nov 26, 2017

Codecov Report

Merging #39 into master will increase coverage by 1.18%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #39      +/-   ##
==========================================
+ Coverage    88.4%   89.58%   +1.18%     
==========================================
  Files           9        9              
  Lines         345      365      +20     
==========================================
+ Hits          305      327      +22     
+ Misses         40       38       -2
Impacted Files Coverage Δ
src/blockarray.jl 100% <100%> (+3.12%) ⬆️
src/blocksizes.jl 85.18% <100%> (+0.87%) ⬆️
src/pseudo_blockarray.jl 91.37% <100%> (+0.63%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d59bb0e...6cdf3ff. Read the comment docs.

@fredrikekre
Copy link
Member

Cool! how would I implement that?

JuliaLang/Compat.jl#417

## Creating initialized `BlockArrays`

A block array can be created with initialized blocks using the `BlockArray{T}(block_sizes)`
function. The block_sizes are each an `AbstractVector{Int}` which determines the size of the blocks in that dimension. We here create a `[1,2]×[3,2]` block matrix of `Float32`s:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should mention that the arrays themselves are initialized, the values in them are not? What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this behaviour going to change in 0.7 so that Matrix{Float64}(n,m) automatically sets the values?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it will, but not sure.

Copy link
Member Author

@dlfivefifty dlfivefifty Nov 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused about the difference between Matrix{Float64}(uninitialized, n, m) and Matrix{Float64}(n, m).

I'm worried that there's a confusion between uninitialized blocks and uninitialized entries with using uninitialized to mean uninitialized blocks. Especially since I'm hoping to making PseudoBlockArray and BlockArray have equivalent behaviour for the same syntax.

It might be better to add a UninitializedBlocks and then we have the following three cases:

  1. BlockArray{Float64}(uninitialized_blocks, ns), which does not initialize the blocks, i.e., A.blocks[1] is #undef. This is the current behaviour of BlockArray(Vector{Float64}, ns)
  2. BlockArray{Float64}(uninitialized, ns), which initializes the blocks, but not the entries of the blocks, i.e., A.blocks[1] is allocated as a Vector{Float64}(uninitialized, ns[1])
  3. BlockArray{Float64}(ns), which does initialize the blocks, and the entries, i.e., A.blocks[1] is allocated as a Vector{Float64}(ns[1])
  4. PseudoBlockArray{Float64}(uninitialized, ns), A. blocks is allocated as a Vector{Float64}(uninitialized, sum(ns))
  5. PseudoBlockArray{Float64}(ns), which does initialize the blocks, and the entries, i.e., A.blocks is allocated as a Vector{Float64}(sum(ns))

@@ -23,13 +38,13 @@ julia> BlockArray(Matrix{Float32}, [1,2], [3,2])
We can also use a `SparseVector` or any other user defined array type:

```jl
julia> BlockArray(SparseVector{Float64, Int}, [1,2])
julia> BlockArrays._BlockArray(SparseVector{Float64, Int}, [1,2])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this should be updated to use uninitialized?

@dlfivefifty
Copy link
Member Author

@KristofferC The checks now pass, are you happy for this to be merged?

@@ -60,6 +60,32 @@ PseudoBlockArray(blocks::R, block_sizes::Vararg{AbstractVector{Int}, N}) where {
PseudoBlockArray(blocks, Vector{Int}.(block_sizes)...)



@inline function PseudoBlockArray{T}(block_sizes::BlockSizes{N}) where {T, N}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably all these new PseudoBlockArray constructors should use uninitialized?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think you are right, even if the package supports 0.6.

My only hesitation is that sometimes changes in Julia master are backtracked on, but in this case that’s unlikely to happen.

@@ -1,2 +1,2 @@
julia 0.6
Compat 0.30.0
Compat 0.38.0
Copy link
Member

@fredrikekre fredrikekre Dec 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compat 0.39

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't depend on anything in Compat 0.39 that's not in Compat 0.38, so I think this should be left.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compat 0.38 is broken. Please update to 0.39.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote this and then I merged 20 seconds later. Oh well, will update on master.

@KristofferC KristofferC merged commit d88a881 into master Dec 2, 2017
@KristofferC KristofferC deleted the dl/fillarrays branch December 2, 2017 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants